////
//
/// \file ./include/inc/parser/scoped_name_node.hpp
//
//  Copyright 2007, 2008 Chandler Carruth
//
//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
//  use this file except in compliance with the License.  You may obtain a copy
//  of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
//  License for the specific language governing permissions and limitations
//  under the License.
//
////

#ifndef inc_parser_scoped_name_node_header
#define inc_parser_scoped_name_node_header

#include <string>
#include <vector>

#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>

#include <inc/parser/parse_tree_node.hpp>

namespace inc {
namespace parser {

class InternalNameNode;
class LabelNode;

/// \brief  Parse node for scoped names
/// \author Chandler Carruth
/// \date   2007.07.26
///
/// This represents a scope-adjusted named value in the parse tree. It can
/// represent both popping the scope out of the procedural nesting to the
/// object member scope, and popping the scope yet again to the program object
/// level. It also represents any sub-scope chain attached to a particular name
/// resolution.
/// 
/// TODO: This class needs better names for the chain of labels used to
/// conveniently select through a set of scopes. Currently this is referred to
/// as a name chain, but that is moderately misleading, as they are not proper
/// names, but are restricted to basic labels to optimize the common case and
/// preserve grouping with more complex constructs.

class ScopedNameNode : public ParseTreeNode
{
public:
  typedef std::vector< boost::shared_ptr< LabelNode > > NameChain;

  ScopedNameNode();
  virtual ~ScopedNameNode();

  virtual bool parse( const iterator& first,
                      const iterator& last,
                      iterator& last_parsed );

  /// Query whether this name is resolved at its object's scope.
  virtual bool is_object_scoped() const { return object_scoped; };

  /// Query whether this name is resolved at its program's scope.
  virtual bool is_program_scoped() const { return program_scoped; };

  /// Access the base scoped name
  virtual InternalNameNode* get_base_name() const { return base_name.get(); }

  /// Query whether we have a chain of sub-scoping names
  virtual bool has_chain() const { return !name_chain.empty(); }

  /// Query the length of the chain of sub-scoping names
  virtual size_t chain_length() const { return name_chain.size(); }

  /// First iterator over the chain of sub-scoping names
  virtual NameChain::const_iterator chain_first() const
      { return name_chain.begin(); }

  /// Last iterator over the chain of sub-scoping names
  virtual NameChain::const_iterator chain_last() const
      { return name_chain.end(); }

private:
  bool object_scoped;
  bool program_scoped;

  boost::scoped_ptr< InternalNameNode > base_name;
  NameChain name_chain;
};

} //  end parser namespace
} //  end inc namespace
#endif  //  inc_parser_scoped_name_node_header
